#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
调试序列LSTM增强模式预测问题
"""

import sys
import os
from PyQt5.QtWidgets import QApplication

# 添加项目根目录到路径
project_root = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, project_root)

def debug_sequence_lstm_prediction():
    """调试序列LSTM增强模式预测"""
    print(" 调试序列LSTM增强模式预测")
    print("=" * 60)
    
    try:
        from lottery_predictor_app import LotteryPredictorApp
        
        # 创建应用实例
        if not QApplication.instance():
            app = QApplication(sys.argv)
        
        predictor = LotteryPredictorApp()
        print(" 成功创建LotteryPredictorApp实例")
        
        # 检查模型文件是否存在
        model_path = os.path.join(predictor.base_dir, 'scripts', 'plw', 'plw_sequence_lstm_model.pth')
        print(f"📁 模型文件路径: {model_path}")
        print(f"📁 模型文件是否存在: {os.path.exists(model_path)}")
        
        if os.path.exists(model_path):
            file_size = os.path.getsize(model_path) / (1024 * 1024)
            print(f" 模型文件大小: {file_size:.2f} MB")
        
        # 检查历史数据文件是否存在
        data_path = os.path.join(predictor.base_dir, 'scripts', 'plw', 'plw_history.csv')
        print(f"📁 数据文件路径: {data_path}")
        print(f"📁 数据文件是否存在: {os.path.exists(data_path)}")
        
        if os.path.exists(data_path):
            file_size = os.path.getsize(data_path) / 1024
            print(f" 数据文件大小: {file_size:.2f} KB")
        
        # 尝试获取序列LSTM增强模式预测
        print("\n🔄 尝试获取序列LSTM增强模式预测...")
        try:
            predictions = predictor.get_enhanced_lstm_predictions("plw", 2)
            print(f"✅ 预测完成，返回结果数量: {len(predictions)}")
            
            if predictions:
                for i, pred in enumerate(predictions, 1):
                    print(f"  第{i}组预测: {pred}")
            else:
                print("⚠️ 预测返回空结果")
                
        except Exception as e:
            print(f" 预测过程中发生错误: {e}")
            import traceback
            print(traceback.format_exc())
        
        print("\n✅ 调试完成")
        
    except Exception as e:
        print(f" 调试失败: {e}")
        import traceback
        print(traceback.format_exc())

if __name__ == "__main__":
    debug_sequence_lstm_prediction()